﻿using System;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Collections.ObjectModel;
using IndexMarkSilverlightClient;

namespace IndexMarkSilverlightClient.IndexMarkServiceReference
{
    public partial class User
    {
        public bool Containts(Characteristic Char, Respondent Resp)
        {
            bool HasEditChar = false;
            bool HasEditResp = false;
            foreach (Permission Perm in Permissions)
            {
                if (Perm.Char.ID == Char.ID) HasEditChar = true;

                if (Perm.Departments.Count == 0)
                    HasEditResp = true;
                else
                    foreach (Department Dep in Perm.Departments)
                    {
                        if (Dep.ContaintsResp(Resp))
                        {
                            HasEditResp = true;
                        }
                    }
            }
            //MessageBox.Show(Resp.FullName + " - " + Char.Name  + Char.Name + "\n"
            //    + string.Join("; ", Permissions.Select(x => x.Char.Name
            //    + ": " + string.Join(", ", x.Departments.Select(y => y.Name).ToArray())).ToArray()));
            //return true;

            return HasEditResp && HasEditChar;
        }

        internal bool IsResponsible(Characteristic Char)
        {
            //MessageBox.Show(Char.Name + Char.ID + "\n" + string.Join("; ",
            //    Permissions.Select(x => x.Char.Name + x.Char.ID).ToArray()));

            foreach (Permission Perm in Permissions)
            {
                if (Perm.Char.ID == Char.ID)
                {
                    return true;
                }
            }
            //MessageBox.Show(Char.Name + "-");
            return false;
        }
    }
}